const knex = require('./conn');

async function table({name, cond}) {
  console.log('fetching table', name, cond);
  let data;
  if (cond === undefined || (cond instanceof Object && Object.keys(cond).length === 0)) {
    console.log('undefined', cond);
    data = await knex(name);
    console.log(data);
  } else {
    data = await knex(name).where(cond);
  }
  return {name, data};
}

async function entry({name, cond={}}) {
  const data = await knex(name).where(cond);
  return {name, data};
}

module.exports = {
  table,
  entry
}